package com.ruoyi.web.controller.systembasic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesWorkCenter;
import com.ruoyi.mes.systembasic.service.ISmesWorkCenterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作中心管理Controller
 *
 * @author simpsense
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/systembasic/workCenter")
public class SmesWorkCenterController extends BaseController
{
    @Autowired
    private ISmesWorkCenterService smesWorkCenterService;

    /**
     * 查询工作中心管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesWorkCenter smesWorkCenter)
    {
        startPage();
        List<SmesWorkCenter> list = smesWorkCenterService.selectSmesWorkCenterList(smesWorkCenter);
        return getDataTable(list);
    }

    /**
     * 导出工作中心管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:export')")
    @Log(title = "工作中心管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesWorkCenter smesWorkCenter)
    {
        List<SmesWorkCenter> list = smesWorkCenterService.selectSmesWorkCenterList(smesWorkCenter);
        ExcelUtil<SmesWorkCenter> util = new ExcelUtil<SmesWorkCenter>(SmesWorkCenter.class);
        return util.exportExcel(list, "workCenter");
    }

    /**
     * 获取工作中心管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:query')")
    @GetMapping(value = "/{workCenterNo}")
    public AjaxResult getInfo(@PathVariable("workCenterNo") String workCenterNo)
    {
        return AjaxResult.success(smesWorkCenterService.selectSmesWorkCenterById(workCenterNo));
    }

    /**
     * 新增工作中心管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:add')")
    @Log(title = "工作中心管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesWorkCenter smesWorkCenter)
    {
        return toAjax(smesWorkCenterService.insertSmesWorkCenter(smesWorkCenter));
    }

    /**
     * 修改工作中心管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:edit')")
    @Log(title = "工作中心管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesWorkCenter smesWorkCenter)
    {
        return toAjax(smesWorkCenterService.updateSmesWorkCenter(smesWorkCenter));
    }

    /**
     * 删除工作中心管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:workCenter:remove')")
    @Log(title = "工作中心管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workCenterNos}")
    public AjaxResult remove(@PathVariable String[] workCenterNos)
    {
        return toAjax(smesWorkCenterService.deleteSmesWorkCenterByIds(workCenterNos));
    }
}